﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;
using YakShaver.Contract;
using YakShaver.YakServer;
using System.Net.Mail;
using YakShaver.CodePlex;
namespace YakShaver.Tests
{
    /// <summary>
    /// Summary description for CodePlexUnitTests
    /// </summary>
    [TestClass]
    public class CodePlexUnitTests
    {
        public CodePlexUnitTests()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod, TestProperty("Category", @"CodePlex\Unit Tests\Notification")]
        public void CodePlexNotificationService_NotifyTest()
        {
            CodePlexNotificationService notificationService = new YakShaver.CodePlex.CodePlexNotificationService(UnitTestHelper.GetSmtpClient(TestContext));
            IWorkItemDataContract mockedDataContract = null;
            MockRepository mocks = new MockRepository();
            int notifyCount = 0;

            mockedDataContract = mocks.CreateMock<IWorkItemDataContract>();
            
            mocks.Record();

            mocks.Replay(mockedDataContract);

            
            bool retVal = notificationService.NotifyForIntervention(notifyCount, mockedDataContract);

            mocks.VerifyAll();

            Assert.AreEqual<bool>(retVal, true, "according to the ntoification service the notify service was not called.");


        }

        [TestMethod(), TestProperty("Category", "CodePlex")]
        public void TestCodePlexAnalysisServiceImplementation()
        {
            MockRepository mocks = new MockRepository();

            //IAnalysisService analysisService = new YakShaver.CodePlex.YakShaverCodePlexService();
            //IWorkItemDataContract dataContract = mocks.Stub<IWorkItemDataContract>();
            //YakShaverWorkItem mockWorkItem = mocks.Stub<YakShaverWorkItem>();

            //mocks.Record();

            //dataContract.Description = "Test Description";
            //dataContract.PageId = "/home/test.aspx";
            //dataContract.WorkItemImpactType = WorkItemImpactType.Unknown;
            //dataContract.WorkItemType = WorkItemType.Unknown;

            //mocks.ReplayAll();

            //YakShaverWorkItem returnValue = analysisService.AnalyzeSubmittedWorkItem(ref dataContract);

            //Assert.IsNotNull(returnValue, "No YakShaverWorkItemInstance returned");
            //Assert.AreNotEqual(returnValue.Component, string.Empty, "Empty Component Value");
            //Assert.AreNotEqual(returnValue.Description, string.Empty, "Empty Description Value");
            //Assert.AreEqual(returnValue.Status, WorkItemSubmissionStatus.NeedIntervention, "Apparently didn't need intervention.. it should.");
            //Assert.AreNotEqual(returnValue.WorkItemImpactType, WorkItemImpactType.Unknown);
            //Assert.AreNotEqual(returnValue.WorkItemType, WorkItemType.Unknown);

        }

    }
}
